package com.ycfmedical.bed.ui.fragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;

import com.ycfmedical.bed.ControlBedConstants;
import com.ycfmedical.bed.base.BaseControlFragment;
import com.ycfmedical.bed.base.BaseFragmentList;
import com.ycfmedical.bed.factory.OrderFactory;
import com.ycfmedical.bed.utils.ConvertOrderCheckoutUtil;
import com.ycfmedical.bed.wifi.WifiEvent;

import java.util.List;

/**
 * Created by yf on 2017-04-05.
 */

public class BedControlFragment extends BaseControlFragment {

    public static ControlCrpFragment crpFragment;
    @Override
    public void initData(Bundle savedInstanceState)
    {
        super.initData(savedInstanceState);
        fragmentsViewPager.setNoScroll(true);
        fragmentsTab.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener()
        {
            @Override
            public void onTabSelected(TabLayout.Tab tab)
            {
                if (tab.getPosition() == 3)
                {
                    ControlCrpFragment crpFragment = BedControlFragment.getControlCrpFragment();
                    crpFragment.restart();
                    // CRP(急救体位（发送特定指令）)
                    String CrpPostStr = ConvertOrderCheckoutUtil
                            .instructCheckOut(OrderFactory.getMessage(ControlBedConstants.CONTROL_POST_CRP));
                    WifiEvent wifi = WifiEvent.getInstance();
                    wifi.senddata(CrpPostStr);
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab)
            {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
        fragmentsTab.getTabAt(3);
    }

    @Override
    protected void addFragmentList(List<Fragment> fragmentList)
    {
        fragmentList.add(ControlFreedomFragment.newInstance());
        fragmentList.add(ControlQuicklyFragment.newInstance());
//        fragmentList.add(ControlnNurseFragment.newInstance());
//        crpFragment = ControlCrpFragment.newInstance();
//        fragmentList.add(crpFragment);
    }

    public static ControlCrpFragment getControlCrpFragment()
    {
        return crpFragment;
    }
    @Override
    protected String[] addTabTitle(String[] titles)
    {
        return new String[] {"自由调整", "一键体位", "护理体位", "CPR"};
    }

    public static BedControlFragment newInstance()
    {
        return new BedControlFragment();
    }
}
